a = int(input())
if a // 1000 == 0:
    print(0)
elif a // 10000 > 0:
    print(0)
else:
    b = a % 10
    c = a // 10 % 10
    d = a // 100 % 10
    e = a // 1000 % 10
    f = a // 100
    g = a // 10 % 100
    h = a % 100
    i = a // 10
    j = a % 1000
    l = 2
    if b == 0 or 1:
        b = 0
    else:
        k = b / l
        while int(k) != k:
            l += 1
            k = b / l
        if b != l:
            b = 0
        elif b == l:
            b = b
    l = 2
    if c == 0 or 1:
        c = 0
    else:
        m = c / l
        while int(m) != m:
            l += 1
            m = c / l
        if c != l:
            c = 0
        elif c == l:
            c = c
    l = 2
    if d == 0 or 1:
        d = 0
    else:
        n = d / l
        while int(n) != n:
            l += 1
            n = d / l
        if d != l:
            d = 0
        elif d == l:
            d = d
    l = 2
    if e == 1:
        e = 0
    else:
        o = e / l
        while int(o) != o:
            l += 1
            o = e / l
        if e != l:
            e = 0
        elif e == l:
            e = e
    l = 2
    p = f / l
    while int(p) != p:
        l += 1
        p = f / l
    if f != l:
        f = 0
    elif f == l:
        f = f
    l = 2
    if g // 10 == 0:
        g = 0
    else:
        q = g / l
        while int(q) != q:
            l += 1
            q = g / l
        if g != l:
            g = 0
        elif g == l:
            g = g
    l = 2
    if h // 10 == 0:
        h = 0
    else:
        r = h / l
        while int(r) != r:
            l += 1
            r = h / l
        if h != l:
            h = 0
        elif h == l:
            h = h
    l = 2
    s = i / l
    while int(s) != s:
        l += 1
        s = i / l
    if i != l:
        i = 0
    elif i == l:
        i = i
    l = 2
    if j // 100 == 0:
        j = 0
    else:
        t = j / l
        while int(t) != t:
            l += 1
            t = j / l
        if j != l:
            j = 0
        elif j == l:
            j = j
    l = 2
    u = a / l
    while int(u) != u:
        l += 1
        u = a / l
    if a != l:
        a = 0
    elif a == l:
        a = a
    v = max(a, b, c, d, e, f, g, h, i, j)
    print(v)